package 排序算法;

import java.util.Arrays;

/**
 * @Author：小鹿爱吃鱼
 * @Date: 2025/5/3 17:16
 * @Description:
 */
public class 冒泡排序 {

    public static void main(String[] args) {
        int[] array = {1,5,3,4,2};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }

    /**
     * O(N^2)
     * @param array
     */
    public static void bubbleSort(int[] array){
        for(int i = 0; i < array.length - 1; i++){
            for(int j = 0; j < array.length - i - 1; j++){
                if(array[j] > array[j+1]){
                    int temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                }
            }
        }


    }


}
